package com.sofwin.entity;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.http.ResponseEntity;

/**
 * ClassName: ResponseEntity
 * Description: TODO
 * date: 2022/4/26 3:01 下午
 *
 * @author andyliu
 * @qq 115176513
 * @since JDK 1.8
 */
@ApiModel(description = "响应的实体类")
@Data
public class AjaxResult {
    @ApiModelProperty(notes = "响应状态吗")
    private Integer code;
    @ApiModelProperty(notes = "响应信息")
    private String msg;
    @ApiModelProperty(notes="响应结果")
    private Object data;

    public AjaxResult(){

    }
    public AjaxResult(Integer code,String msg,Object data){
        this.code = code;
        this.msg=msg;
        this.data = data;
    }

    /**
     * 操作成功的响应结果
     * @param msg 带响应信息
     * @param result
     * @return
     */
    public static AjaxResult success(String msg,Object data){
        return new AjaxResult(200,msg,data);
    }

    /**
     * 不带响应信息的成功数据
     * @param data
     * @return
     */
    public static AjaxResult success(Object data){
        return  new AjaxResult(200,"操作成功",data);
    }

    /**
     * 错误操作的响应
     * @param code
     * @param msg
     * @param data
     * @return
     */
    public static AjaxResult error(Integer code,String msg,Object data){
        return new AjaxResult(code,msg,data);
    }

    /**
     * 错误操作的响应
     * @param msg
     * @param data
     * @return
     */
    public static AjaxResult error(String msg,Object data){
        return new AjaxResult(500,msg,data);
    }
    /**
     * 错误操作的响应
     * @param data
     * @return
     */
    public static AjaxResult error(Object data){
        return new AjaxResult(500,"操作失败",data);
    }
}
